﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DevPhone.Controls;
using DevPhoneToolkitSample.Data;
using Microsoft.Phone.Controls;

namespace DevPhoneToolkitSample.Samples
{
    public partial class CalendarControlTodaySample : PhoneApplicationPage
    {
        private static IEnumerable<ColorItem> CreateListColors()
        {
            return new List<ColorItem>()
                       {
                           new ColorItem {Text = "Default", Color = Colors.Transparent},
                           new ColorItem {Text = "orange", Color = Colors.Orange},
                           new ColorItem {Text = "red", Color = Colors.Red},
                           new ColorItem {Text = "blue", Color = Colors.Blue},
                           new ColorItem {Text = "magenta", Color = Colors.Magenta},
                           new ColorItem {Text = "purple", Color = Colors.Purple},
                           new ColorItem {Text = "green", Color = Colors.Green},
                           new ColorItem {Text = "cyan", Color = Colors.Cyan},
                           new ColorItem {Text = "brown", Color = Colors.Brown},
                           new ColorItem {Text = "yellow", Color = Colors.Yellow},
                       };
        }

        public CalendarControlTodaySample()
        {
            InitializeComponent();
            CboToday.ItemsSource = CreateListColors();
        }

        private void CboTodayMarkSelectionChange(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems[0].ToString() == "Underline" || e.AddedItems[0].ToString() == "None")
            {
                CboToday.Visibility = Visibility.Collapsed;
                CboMarkPosition.Visibility = Visibility.Collapsed;
                CboMarkWidth.Visibility = Visibility.Collapsed;
            }
            else if (e.AddedItems[0].ToString() == "MarkDate" )
            {
                CboToday.Visibility = Visibility.Visible;
                CboMarkPosition.Visibility = Visibility.Visible;
                CboMarkWidth.Visibility = Visibility.Visible;
            }
            else
            {
                CboToday.Visibility = Visibility.Visible;
            }
            Calend.TodayHighlight =
                (CalendarHighlightToday) Enum.Parse(typeof (CalendarHighlightToday), e.AddedItems[0].ToString(), true);
        }

        private void CboTodaySelectionChange(object sender, SelectionChangedEventArgs e)
        {
            var item = (ColorItem) e.AddedItems[0];
            Calend.TodayBrush = item.Text == "Default" ? null : new SolidColorBrush(item.Color);
        }

        private void CalendarControlChangeSelectDate(object sender,CalendarChangeSelectDateEventArgs e)
        {
            MessageBox.Show("Selected Date: " + e.Date.ToShortDateString());
        }

        private void CboMarkPositionSelectionChange(object sender, SelectionChangedEventArgs e)
        {
            Calend.MarkPosition =
                (CalendarPositionMark) Enum.Parse(typeof (CalendarPositionMark), e.AddedItems[0].ToString(), true);
        }

        private void CboMarkWidthSelectionChange(object sender, SelectionChangedEventArgs e)
        {
            Calend.MarkWidth =
                (CalendarMarkWidth)Enum.Parse(typeof(CalendarMarkWidth), e.AddedItems[0].ToString(), true);
        }

    }
}